package com.cloudweb.oa.filter;

/*import org.apache.struts2.dispatcher.ActionContextCleanUp;
import org.apache.struts2.dispatcher.FilterDispatcher;
import org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter;*/
import com.cloudweb.oa.utils.ConfigUtil;
import com.cloudweb.oa.utils.FileUtil;
import com.cloudweb.oa.utils.SpringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import org.springframework.core.Ordered;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

import java.util.ArrayList;
import java.util.List;

@DependsOn("SpringUtil")
@Configuration
public class FilterConfig {

    /**
     * 配置允许跨域，此filter需启用，因为CorsFilter中指定了需JWT需暴露的header
     * @return
     */
    @Bean
    public FilterRegistrationBean registerFilter() {
        FilterRegistrationBean<CorsFilter> bean = new FilterRegistrationBean<>();

        List<String> list = new ArrayList<>();
        /*list.add("/document/*"); // xiaocaicloud.com
        list.add("/public/app/*"); // 手机端
        list.add("/mobile/*"); // 小程序端登录
        list.add("/modular/*"); // 小程序端智能模块
        list.add("/mini/*"); // 小程序端接口
        list.add("/i/*"); // 小程序端接口，我*/

        bean.addUrlPatterns("/*");

        bean.setFilter(new CorsFilter());
        // 过滤顺序，从小到大依次过滤
        bean.setOrder(Ordered.HIGHEST_PRECEDENCE);
        // bean.addInitParameter("exclusions","/some,/hello");
        return bean;
    }
}
